import os
import requests
from tqdm import tqdm


def download_file(url, file_path):
    """

    :param url: 下载路径
    :param file_path: 文件路径
    :return:
    """
    if os.path.exists(file_path):
        return
    else:
        print(f'File {file_path} does not exist. Downloading from {url}')
        response = requests.get(url, stream=True)
        total_size = int(response.headers.get('content-length', 0))
        block_size = 1024  # 1 KB

        with open(file_path, 'wb') as file, tqdm(
                desc=file_path,
                total=total_size,
                unit='B',
                unit_scale=True,
                unit_divisor=1024,
        ) as bar:
            for data in response.iter_content(block_size):
                bar.update(len(data))
                file.write(data)
        print(f'File downloaded successfully: {file_path}')
